// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    username:'',
    password:'',
    usertext:true,
    passtext:true
  },
  // 事件处理函数
  getUsername:function(t){
    this.setData({
      username:t.detail.value
    })
  },
  getPassword:function(t){
    this.setData({
      password:t.detail.value
    })
  },
  login() {

    wx.request({
      url:'https://yali.geekwhite.cn:3000/login', 
      header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        username:this.data.username,
        password:this.data.password,
       },
       method: 'post',
       success: res=>{
            // console.log(res.data.name);
            let user=this.data.usertext;
            let pass=this.data.passtext;
            let test;
            console.log(res.data,0);
            if(res.data=='该用户名不存在'){
             user=false;
             pass=true
            }
            if(res.data=='密码错误'){
             pass=false;
             user=true
            }
            if(res.data.bool==true){
              user=true;
              pass=true;
             
              console.log(res.data.name)
              wx.setStorageSync('username', this.data.username);
              wx.setStorageSync('name', res.data.name)
              wx.setStorageSync('password', this.data.password);
              // console.log(wx.getStorageSync('username'))
              wx.switchTab({
                url: '../home/home'
                // url:'../day/day'
              })
            }
            this.setData({
              usertext:user,
              passtext:pass
            })
            // console.log(this.data.usertext) 
            // console.log(this.data.passtext) 
       }
    })

  },



})
